package com;

import com.SoftKey;
import com.softkey.jsyunew3;
import org.junit.Test;

/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'Class1'
 * created in the main() method.
 */
public class test
{
    /**
     * The main entry point for the application.
     *
     * @param args Array of parameters passed to the application
     * via the command line.
     */
    public static void main (String[] args)
    {
        // TODO: Add initialization code here
        int ret;
        SoftKey ytsoftkey = new SoftKey();
        String DevicePath;
        //这个用于判断系统中是否存在着加密锁。不需要是指定
        // 的加密锁,
        DevicePath = ytsoftkey.FindPort(0);
        System.out.println(DevicePath);
        if(ytsoftkey.get_LastError()!=0)
        {
            System.out.println("未找到加密锁,请插入加密锁后，再进行操作。");
            return ;
        }
        System.out.println(ytsoftkey.get_LastError());


        //使用增强算法一来检查是否存在指定的加密锁
        ret = ytsoftkey.CheckKeyByEncstring();
        if (ret == 1)
        {
            System.out.println( "你生成加密代码时没有设置该函数");
            return ;
        }
        if (ret == 0)
        {
            System.out.println("使用增强算法一来检查:找到指定的加密锁");
        }
        else
        {
            System.out.println("使用增强算法一来检查:未能找到指定的加密锁"); return;
        }



        //使用读写储存器来检查是否存在指定的加密锁
        ret = ytsoftkey.CheckKeyByReadEprom();
        if (ret == 1)
        {
            System.out.println("你生成加密代码时没有设置该函数");
            return;
        }
        if (ret == 0)
        {
            System.out.println("使用读写储存器来检查:找到指定的加密锁");
        }
        else
        {
            System.out.println("使用读写储存器来检查:未能找到指定的加密锁"); return;
        }

/*2953800*/
        System.out.println(ytsoftkey.StrEnc("Early123.", "1203721912CA79D8"));
        System.out.println(ytsoftkey.StrDec("2A876B3DB20DC8DF2E00","1203721912CA79D8"));
    }

    @Test
    public void test2() {
        SoftKey softKey = new SoftKey();
        jsyunew3 j9 = softKey.getj9();
        String path = j9.FindPort(0);
        System.out.println();j9.SM2_EncString("wuyukasgjklasdjkljl", "");
        //        j9.SM2_DecString()
    }

    @Test
    public void test1() {
        SoftKey softKey = new SoftKey();
        jsyunew3 j9 = softKey.getj9();
        String path = j9.FindPort(0);
        short data = (short) 5;
        System.out.println(j9.SetEncBuf(6,data ));
        System.out.println(j9.Cal(path));
        System.out.println(j9.GetEncBuf(1));
    }

    @Test
    public void test(){
        SoftKey softKey=new SoftKey();
        jsyunew3 j9=softKey.getj9();
//        softKey.getj9().SetCal_2("", "");// 设置增加算法密钥

        System.out.println(j9.StarGenKeyPair(j9.FindPort(0)));
//        System.out.println(softKey.getj9().EncString("aaaaa", ""));
//        System.out.println(softKey.getj9().DecString("2A50C9FF9DCEB87A", "C35094512C0179CADA4C1FEB8F2BE313"));
        String pri_key = j9.get_GenPriKey();
        String pub_keyx = j9.get_GenPubKeyX();
        String pub_keyy = j9.get_GenPubKeyY();

        System.out.println(pri_key);
        System.out.println(pub_keyx);
        System.out.println(pub_keyy);
        System.out.println(j9.Set_SM2_KeyPair(pri_key,pub_keyx,pub_keyy,"wuyu,123456",j9.FindPort(0)));

        System.out.println(softKey.getj9().GetPubKeyX(j9.FindPort(0)));
        System.out.println(softKey.getj9().GetPubKeyY(j9.FindPort(0)));
        System.out.println(j9.GetChipID(j9.FindPort(0)));
        System.out.println(j9.GetSm2UserName(j9.FindPort(0)));



//// 默认那第一个的key
        int a = (int) softKey.getj9().GetID_1("");
        String hex1 = Integer.toHexString(a).toUpperCase();
        System.out.println("hex1 :"+hex1);
        a = (int) softKey.getj9().GetID_2("");
        String hex2 = Integer.toHexString(a).toUpperCase();
        System.out.println("hex2 :"+hex2);
        System.out.println(hex1+hex2);

    }

    @Test
    public void test3() {
        SoftKey softKey = new SoftKey();
        System.out.println(softKey.StrEnc("Early123.", "1201B44F12C8BC0E"));
        System.out.println(softKey.StrDec("98CACC11F66251682E00","1201B44F12C8BC0E"));
    }

    @Test
    public void test5(){
        SoftKey softKey=new SoftKey();
        jsyunew3 j9=softKey.getj9();
        int a = (int) softKey.getj9().GetID_1("");
        String hex1 = Integer.toHexString(a).toUpperCase();
        System.out.println("hex1 :"+hex1);
        a = (int) softKey.getj9().GetID_2("");
        String hex2 = Integer.toHexString(a).toUpperCase();
        System.out.println("hex2 :"+hex2);
        System.out.println(hex1+hex2);
    }
}
